package com.cxhc.common.utils;


import com.cxhc.common.constant.UserConstants;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 密码工具类
 *
 * @author wuxuan
 */
public class PassWordUtils {

    private static final Logger log = LoggerFactory.getLogger(PassWordUtils.class);

    /**
     * 密码正则表达式
     * 必须包含大小写字母、数字和@字符，长度在8位以上
     */
    private static final String PASSWORD_REGEX = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[@]).{8,}$";

    public static boolean validatePassword(String password) {
        if ( !password.matches(PASSWORD_REGEX) ) {
            return false;
        }
        return true;
    }


    public static String getDefaultPassword(String phone) {
        String password = UserConstants.DEFAULT_PASSWORD;
        try {
            if (StringUtils.isNotEmpty(phone)){
                password = UserConstants.DEFAULT_PASSWORD.substring(0,5) + phone.substring(7);
            }
        } catch (Exception e) {
            log.info("密码初始化异常使用默认密码！！！");
        }
        return password;
    }
}
